home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume24 / gnudiff1.15 / part02 < prev    next >
Encoding:
Internet Message Format  |  1991-03-05  |  47.8 KB

  1. Subject:  v24i017:  GNU Diff, version 1.15, Part02/08
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: 0ddde865 39dd146b cb649012 1dd9e34f
  5.  
  6. Submitted-by: Paul Eggert <eggert@twinsun.com>
  7. Posting-number: Volume 24, Issue 17
  8. Archive-name: gnudiff1.15/part02
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 2 (of 8)."
  17. # Contents:  COPYING context.c diff.h regex.h
  18. # Wrapped by eggert@ata on Mon Jan  7 11:25:28 1991
  19. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  20. if test -f 'COPYING' -a "${1}" != "-c" ; then 
  21.   echo shar: Will not clobber existing file \"'COPYING'\"
  22. else
  23. echo shar: Extracting \"'COPYING'\" \(12488 characters\)
  24. sed "s/^X//" >'COPYING' <<'END_OF_FILE'
  25. X
  26. X            GNU GENERAL PUBLIC LICENSE
  27. X             Version 1, February 1989
  28. X
  29. X Copyright (C) 1989 Free Software Foundation, Inc.
  30. X                    675 Mass Ave, Cambridge, MA 02139, USA
  31. X Everyone is permitted to copy and distribute verbatim copies
  32. X of this license document, but changing it is not allowed.
  33. X
  34. X                Preamble
  35. X
  36. X  The license agreements of most software companies try to keep users
  37. Xat the mercy of those companies.  By contrast, our General Public
  38. XLicense is intended to guarantee your freedom to share and change free
  39. Xsoftware--to make sure the software is free for all its users.  The
  40. XGeneral Public License applies to the Free Software Foundation's
  41. Xsoftware and to any other program whose authors commit to using it.
  42. XYou can use it for your programs, too.
  43. X
  44. X  When we speak of free software, we are referring to freedom, not
  45. Xprice.  Specifically, the General Public License is designed to make
  46. Xsure that you have the freedom to give away or sell copies of free
  47. Xsoftware, that you receive source code or can get it if you want it,
  48. Xthat you can change the software or use pieces of it in new free
  49. Xprograms; and that you know you can do these things.
  50. X
  51. X  To protect your rights, we need to make restrictions that forbid
  52. Xanyone to deny you these rights or to ask you to surrender the rights.
  53. XThese restrictions translate to certain responsibilities for you if you
  54. Xdistribute copies of the software, or if you modify it.
  55. X
  56. X  For example, if you distribute copies of a such a program, whether
  57. Xgratis or for a fee, you must give the recipients all the rights that
  58. Xyou have.  You must make sure that they, too, receive or can get the
  59. Xsource code.  And you must tell them their rights.
  60. X
  61. X  We protect your rights with two steps: (1) copyright the software, and
  62. X(2) offer you this license which gives you legal permission to copy,
  63. Xdistribute and/or modify the software.
  64. X
  65. X  Also, for each author's protection and ours, we want to make certain
  66. Xthat everyone understands that there is no warranty for this free
  67. Xsoftware.  If the software is modified by someone else and passed on, we
  68. Xwant its recipients to know that what they have is not the original, so
  69. Xthat any problems introduced by others will not reflect on the original
  70. Xauthors' reputations.
  71. X
  72. X  The precise terms and conditions for copying, distribution and
  73. Xmodification follow.
  74. X
  75. X            GNU GENERAL PUBLIC LICENSE
  76. X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  77. X
  78. X  0. This License Agreement applies to any program or other work which
  79. Xcontains a notice placed by the copyright holder saying it may be
  80. Xdistributed under the terms of this General Public License.  The
  81. X"Program", below, refers to any such program or work, and a "work based
  82. Xon the Program" means either the Program or any work containing the
  83. XProgram or a portion of it, either verbatim or with modifications.  Each
  84. Xlicensee is addressed as "you".
  85. X
  86. X  1. You may copy and distribute verbatim copies of the Program's source
  87. Xcode as you receive it, in any medium, provided that you conspicuously and
  88. Xappropriately publish on each copy an appropriate copyright notice and
  89. Xdisclaimer of warranty; keep intact all the notices that refer to this
  90. XGeneral Public License and to the absence of any warranty; and give any
  91. Xother recipients of the Program a copy of this General Public License
  92. Xalong with the Program.  You may charge a fee for the physical act of
  93. Xtransferring a copy.
  94. X
  95. X  2. You may modify your copy or copies of the Program or any portion of
  96. Xit, and copy and distribute such modifications under the terms of Paragraph
  97. X1 above, provided that you also do the following:
  98. X
  99. X    a) cause the modified files to carry prominent notices stating that
  100. X    you changed the files and the date of any change; and
  101. X
  102. X    b) cause the whole of any work that you distribute or publish, that
  103. X    in whole or in part contains the Program or any part thereof, either
  104. X    with or without modifications, to be licensed at no charge to all
  105. X    third parties under the terms of this General Public License (except
  106. X    that you may choose to grant warranty protection to some or all
  107. X    third parties, at your option).
  108. X
  109. X    c) If the modified program normally reads commands interactively when
  110. X    run, you must cause it, when started running for such interactive use
  111. X    in the simplest and most usual way, to print or display an
  112. X    announcement including an appropriate copyright notice and a notice
  113. X    that there is no warranty (or else, saying that you provide a
  114. X    warranty) and that users may redistribute the program under these
  115. X    conditions, and telling the user how to view a copy of this General
  116. X    Public License.
  117. X
  118. X    d) You may charge a fee for the physical act of transferring a
  119. X    copy, and you may at your option offer warranty protection in
  120. X    exchange for a fee.
  121. X
  122. XMere aggregation of another independent work with the Program (or its
  123. Xderivative) on a volume of a storage or distribution medium does not bring
  124. Xthe other work under the scope of these terms.
  125. X
  126. X  3. You may copy and distribute the Program (or a portion or derivative of
  127. Xit, under Paragraph 2) in object code or executable form under the terms of
  128. XParagraphs 1 and 2 above provided that you also do one of the following:
  129. X
  130. X    a) accompany it with the complete corresponding machine-readable
  131. X    source code, which must be distributed under the terms of
  132. X    Paragraphs 1 and 2 above; or,
  133. X
  134. X    b) accompany it with a written offer, valid for at least three
  135. X    years, to give any third party free (except for a nominal charge
  136. X    for the cost of distribution) a complete machine-readable copy of the
  137. X    corresponding source code, to be distributed under the terms of
  138. X    Paragraphs 1 and 2 above; or,
  139. X
  140. X    c) accompany it with the information you received as to where the
  141. X    corresponding source code may be obtained.  (This alternative is
  142. X    allowed only for noncommercial distribution and only if you
  143. X    received the program in object code or executable form alone.)
  144. X
  145. XSource code for a work means the preferred form of the work for making
  146. Xmodifications to it.  For an executable file, complete source code means
  147. Xall the source code for all modules it contains; but, as a special
  148. Xexception, it need not include source code for modules which are standard
  149. Xlibraries that accompany the operating system on which the executable
  150. Xfile runs, or for standard header files or definitions files that
  151. Xaccompany that operating system.
  152. X
  153. X  4. You may not copy, modify, sublicense, distribute or transfer the
  154. XProgram except as expressly provided under this General Public License.
  155. XAny attempt otherwise to copy, modify, sublicense, distribute or transfer
  156. Xthe Program is void, and will automatically terminate your rights to use
  157. Xthe Program under this License.  However, parties who have received
  158. Xcopies, or rights to use copies, from you under this General Public
  159. XLicense will not have their licenses terminated so long as such parties
  160. Xremain in full compliance.
  161. X
  162. X  5. By copying, distributing or modifying the Program (or any work based
  163. Xon the Program) you indicate your acceptance of this license to do so,
  164. Xand all its terms and conditions.
  165. X
  166. X  6. Each time you redistribute the Program (or any work based on the
  167. XProgram), the recipient automatically receives a license from the original
  168. Xlicensor to copy, distribute or modify the Program subject to these
  169. Xterms and conditions.  You may not impose any further restrictions on the
  170. Xrecipients' exercise of the rights granted herein.
  171. X
  172. X  7. The Free Software Foundation may publish revised and/or new versions
  173. Xof the General Public License from time to time.  Such new versions will
  174. Xbe similar in spirit to the present version, but may differ in detail to
  175. Xaddress new problems or concerns.
  176. X
  177. XEach version is given a distinguishing version number.  If the Program
  178. Xspecifies a version number of the license which applies to it and "any
  179. Xlater version", you have the option of following the terms and conditions
  180. Xeither of that version or of any later version published by the Free
  181. XSoftware Foundation.  If the Program does not specify a version number of
  182. Xthe license, you may choose any version ever published by the Free Software
  183. XFoundation.
  184. X
  185. X  8. If you wish to incorporate parts of the Program into other free
  186. Xprograms whose distribution conditions are different, write to the author
  187. Xto ask for permission.  For software which is copyrighted by the Free
  188. XSoftware Foundation, write to the Free Software Foundation; we sometimes
  189. Xmake exceptions for this.  Our decision will be guided by the two goals
  190. Xof preserving the free status of all derivatives of our free software and
  191. Xof promoting the sharing and reuse of software generally.
  192. X
  193. X                NO WARRANTY
  194. X
  195. X  9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  196. XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  197. XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  198. XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  199. XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  200. XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  201. XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  202. XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  203. XREPAIR OR CORRECTION.
  204. X
  205. X  10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  206. XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  207. XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  208. XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  209. XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  210. XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  211. XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  212. XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  213. XPOSSIBILITY OF SUCH DAMAGES.
  214. X
  215. X             END OF TERMS AND CONDITIONS
  216. X
  217. X    Appendix: How to Apply These Terms to Your New Programs
  218. X
  219. X  If you develop a new program, and you want it to be of the greatest
  220. Xpossible use to humanity, the best way to achieve this is to make it
  221. Xfree software which everyone can redistribute and change under these
  222. Xterms.
  223. X
  224. X  To do so, attach the following notices to the program.  It is safest to
  225. Xattach them to the start of each source file to most effectively convey
  226. Xthe exclusion of warranty; and each file should have at least the
  227. X"copyright" line and a pointer to where the full notice is found.
  228. X
  229. X    <one line to give the program's name and a brief idea of what it does.>
  230. X    Copyright (C) 19yy  <name of author>
  231. X
  232. X    This program is free software; you can redistribute it and/or modify
  233. X    it under the terms of the GNU General Public License as published by
  234. X    the Free Software Foundation; either version 1, or (at your option)
  235. X    any later version.
  236. X
  237. X    This program is distributed in the hope that it will be useful,
  238. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  239. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  240. X    GNU General Public License for more details.
  241. X
  242. X    You should have received a copy of the GNU General Public License
  243. X    along with this program; if not, write to the Free Software
  244. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  245. X
  246. XAlso add information on how to contact you by electronic and paper mail.
  247. X
  248. XIf the program is interactive, make it output a short notice like this
  249. Xwhen it starts in an interactive mode:
  250. X
  251. X    Gnomovision version 69, Copyright (C) 19xx name of author
  252. X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  253. X    This is free software, and you are welcome to redistribute it
  254. X    under certain conditions; type `show c' for details.
  255. X
  256. XThe hypothetical commands `show w' and `show c' should show the
  257. Xappropriate parts of the General Public License.  Of course, the
  258. Xcommands you use may be called something other than `show w' and `show
  259. Xc'; they could even be mouse-clicks or menu items--whatever suits your
  260. Xprogram.
  261. X
  262. XYou should also get your employer (if you work as a programmer) or your
  263. Xschool, if any, to sign a "copyright disclaimer" for the program, if
  264. Xnecessary.  Here a sample; alter the names:
  265. X
  266. X  Yoyodyne, Inc., hereby disclaims all copyright interest in the
  267. X  program `Gnomovision' (a program to direct compilers to make passes
  268. X  at assemblers) written by James Hacker.
  269. X
  270. X  <signature of Ty Coon>, 1 April 1989
  271. X  Ty Coon, President of Vice
  272. X
  273. XThat's all there is to it!
  274. END_OF_FILE
  275. if test 12488 -ne `wc -c <'COPYING'`; then
  276.     echo shar: \"'COPYING'\" unpacked with wrong size!
  277. fi
  278. # end of 'COPYING'
  279. fi
  280. if test -f 'context.c' -a "${1}" != "-c" ; then 
  281.   echo shar: Will not clobber existing file \"'context.c'\"
  282. else
  283. echo shar: Extracting \"'context.c'\" \(12479 characters\)
  284. sed "s/^X//" >'context.c' <<'END_OF_FILE'
  285. X/* Context-format output routines for GNU DIFF.
  286. X   Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  287. X
  288. XThis file is part of GNU DIFF.
  289. X
  290. XGNU DIFF is free software; you can redistribute it and/or modify
  291. Xit under the terms of the GNU General Public License as published by
  292. Xthe Free Software Foundation; either version 1, or (at your option)
  293. Xany later version.
  294. X
  295. XGNU DIFF is distributed in the hope that it will be useful,
  296. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  297. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  298. XGNU General Public License for more details.
  299. X
  300. XYou should have received a copy of the GNU General Public License
  301. Xalong with GNU DIFF; see the file COPYING.  If not, write to
  302. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  303. X
  304. X#include "diff.h"
  305. X#include "regex.h"
  306. X
  307. Xstatic void pr_context_hunk ();
  308. Xstatic void pr_unidiff_hunk ();
  309. Xstatic struct change *find_hunk ();
  310. Xstatic void mark_ignorable ();
  311. Xstatic void find_function ();
  312. X
  313. X/* Last place find_function started searching from.  */
  314. Xstatic int find_function_last_search;
  315. X
  316. X/* The value find_function returned when it started searching there.  */
  317. Xstatic int find_function_last_match;
  318. X
  319. X/* Print a label for a context diff, with a file name and date or a label.  */
  320. X
  321. Xstatic void
  322. Xprint_context_label (mark, inf, label)
  323. X     const char *mark;
  324. X     struct file_data *inf;
  325. X     const char *label;
  326. X{
  327. X  if (label)
  328. X    fprintf (outfile, "%s %s\n", mark, label);
  329. X  else if (inf->stat.st_mtime)
  330. X    fprintf (outfile, "%s %s\t%s", mark, inf->name, ctime(&inf->stat.st_mtime));
  331. X  else
  332. X    /* Don't pretend that standard input is ancient.  */
  333. X    fprintf (outfile, "%s %s\n", mark, inf->name);
  334. X}
  335. X
  336. X/* Print a header for a context diff, with the file names and dates.  */
  337. X
  338. Xvoid
  339. Xprint_context_header (inf, unidiff_flag)
  340. X     struct file_data *inf;
  341. X     int unidiff_flag;
  342. X{
  343. X  if (unidiff_flag)
  344. X    {
  345. X      print_context_label ("---", &inf[0], file_label[0]);
  346. X      print_context_label ("+++", &inf[1], file_label[1]);
  347. X    }
  348. X  else
  349. X    {
  350. X      print_context_label ("***", &inf[0], file_label[0]);
  351. X      print_context_label ("---", &inf[1], file_label[1]);
  352. X    }
  353. X}
  354. X
  355. X/* Print an edit script in context format.  */
  356. X
  357. Xvoid
  358. Xprint_context_script (script, unidiff_flag)
  359. X     struct change *script;
  360. X     int unidiff_flag;
  361. X{
  362. X  if (ignore_blank_lines_flag || ignore_regexp)
  363. X    mark_ignorable (script);
  364. X  else
  365. X    {
  366. X      struct change *e;
  367. X      for (e = script; e; e = e->link)
  368. X    e->ignore = 0;
  369. X    }
  370. X
  371. X  find_function_last_search = 0;
  372. X  find_function_last_match = -1;
  373. X
  374. X  if (unidiff_flag)
  375. X    print_script (script, find_hunk, pr_unidiff_hunk);
  376. X  else
  377. X    print_script (script, find_hunk, pr_context_hunk);
  378. X}
  379. X
  380. X/* Print a pair of line numbers with a comma, translated for file FILE.
  381. X   If the second number is not greater, use the first in place of it.
  382. X
  383. X   Args A and B are internal line numbers.
  384. X   We print the translated (real) line numbers.  */
  385. X
  386. Xstatic void
  387. Xprint_context_number_range (file, a, b)
  388. X     struct file_data *file;
  389. X     int a, b;
  390. X{
  391. X  int trans_a, trans_b;
  392. X  translate_range (file, a, b, &trans_a, &trans_b);
  393. X
  394. X  /* Note: we can have B < A in the case of a range of no lines.
  395. X     In this case, we should print the line number before the range,
  396. X     which is B.  */
  397. X  if (trans_b > trans_a)
  398. X    fprintf (outfile, "%d,%d", trans_a, trans_b);
  399. X  else
  400. X    fprintf (outfile, "%d", trans_b);
  401. X}
  402. X
  403. X/* Print a portion of an edit script in context format.
  404. X   HUNK is the beginning of the portion to be printed.
  405. X   The end is marked by a `link' that has been nulled out.
  406. X
  407. X   Prints out lines from both files, and precedes each
  408. X   line with the appropriate flag-character.  */
  409. X
  410. Xstatic void
  411. Xpr_context_hunk (hunk)
  412. X     struct change *hunk;
  413. X{
  414. X  int first0, last0, first1, last1, show_from, show_to, i;
  415. X  struct change *next;
  416. X  char *prefix;
  417. X  char *function;
  418. X  int function_length;
  419. X
  420. X  /* Determine range of line numbers involved in each file.  */
  421. X
  422. X  analyze_hunk (hunk, &first0, &last0, &first1, &last1, &show_from, &show_to);
  423. X
  424. X  if (!show_from && !show_to)
  425. X    return;
  426. X
  427. X  /* Include a context's width before and after.  */
  428. X
  429. X  first0 = max (first0 - context, 0);
  430. X  first1 = max (first1 - context, 0);
  431. X  last0 = min (last0 + context, files[0].buffered_lines - 1);
  432. X  last1 = min (last1 + context, files[1].buffered_lines - 1);
  433. X
  434. X  /* If desired, find the preceding function definition line in file 0.  */
  435. X  function = 0;
  436. X  if (function_regexp)
  437. X    find_function (&files[0], first0, &function, &function_length);
  438. X
  439. X  /* If we looked for and found a function this is part of,
  440. X     include its name in the header of the diff section.  */
  441. X  fprintf (outfile, "***************");
  442. X
  443. X  if (function)
  444. X    {
  445. X      fprintf (outfile, " ");
  446. X      fwrite (function, 1, min (function_length - 1, 40), outfile);
  447. X    }
  448. X
  449. X  fprintf (outfile, "\n*** ");
  450. X  print_context_number_range (&files[0], first0, last0);
  451. X  fprintf (outfile, " ****\n");
  452. X
  453. X  if (show_from)
  454. X    {
  455. X      next = hunk;
  456. X
  457. X      for (i = first0; i <= last0; i++)
  458. X    {
  459. X      /* Skip past changes that apply (in file 0)
  460. X         only to lines before line I.  */
  461. X
  462. X      while (next && next->line0 + next->deleted <= i)
  463. X        next = next->link;
  464. X
  465. X      /* Compute the marking for line I.  */
  466. X
  467. X      prefix = " ";
  468. X      if (next && next->line0 <= i)
  469. X        /* The change NEXT covers this line.
  470. X           If lines were inserted here in file 1, this is "changed".
  471. X           Otherwise it is "deleted".  */
  472. X        prefix = (next->inserted > 0 ? "!" : "-");
  473. X
  474. X      print_1_line (prefix, &files[0].linbuf[i]);
  475. X    }
  476. X    }
  477. X
  478. X  fprintf (outfile, "--- ");
  479. X  print_context_number_range (&files[1], first1, last1);
  480. X  fprintf (outfile, " ----\n");
  481. X
  482. X  if (show_to)
  483. X    {
  484. X      next = hunk;
  485. X
  486. X      for (i = first1; i <= last1; i++)
  487. X    {
  488. X      /* Skip past changes that apply (in file 1)
  489. X         only to lines before line I.  */
  490. X
  491. X      while (next && next->line1 + next->inserted <= i)
  492. X        next = next->link;
  493. X
  494. X      /* Compute the marking for line I.  */
  495. X
  496. X      prefix = " ";
  497. X      if (next && next->line1 <= i)
  498. X        /* The change NEXT covers this line.
  499. X           If lines were deleted here in file 0, this is "changed".
  500. X           Otherwise it is "inserted".  */
  501. X        prefix = (next->deleted > 0 ? "!" : "+");
  502. X
  503. X      print_1_line (prefix, &files[1].linbuf[i]);
  504. X    }
  505. X    }
  506. X}
  507. X
  508. X/* Print a pair of line numbers with a comma, translated for file FILE.
  509. X   If the second number is smaller, use the first in place of it.
  510. X   If the numbers are equal, print just one number.
  511. X
  512. X   Args A and B are internal line numbers.
  513. X   We print the translated (real) line numbers.  */
  514. X
  515. Xstatic void
  516. Xprint_unidiff_number_range (file, a, b)
  517. X     struct file_data *file;
  518. X     int a, b;
  519. X{
  520. X  int trans_a, trans_b;
  521. X  translate_range (file, a, b, &trans_a, &trans_b);
  522. X
  523. X  /* Note: we can have B < A in the case of a range of no lines.
  524. X     In this case, we should print the line number before the range,
  525. X     which is B.  */
  526. X  if (trans_b <= trans_a)
  527. X    fprintf (outfile, trans_b == trans_a ? "%d" : "%d,0", trans_b);
  528. X  else
  529. X    fprintf (outfile, "%d,%d", trans_a, trans_b - trans_a + 1);
  530. X}
  531. X
  532. X/* Print a portion of an edit script in unidiff format.
  533. X   HUNK is the beginning of the portion to be printed.
  534. X   The end is marked by a `link' that has been nulled out.
  535. X
  536. X   Prints out lines from both files, and precedes each
  537. X   line with the appropriate flag-character.  */
  538. X
  539. Xstatic void
  540. Xpr_unidiff_hunk (hunk)
  541. X     struct change *hunk;
  542. X{
  543. X  int first0, last0, first1, last1, show_from, show_to, i, j, k;
  544. X  struct change *next;
  545. X  int lastline;
  546. X  char *function;
  547. X  int function_length;
  548. X
  549. X  /* Determine range of line numbers involved in each file.  */
  550. X
  551. X  analyze_hunk (hunk, &first0, &last0, &first1, &last1, &show_from, &show_to);
  552. X
  553. X  if (!show_from && !show_to)
  554. X    return;
  555. X
  556. X  /* Include a context's width before and after.  */
  557. X
  558. X  first0 = max (first0 - context, 0);
  559. X  first1 = max (first1 - context, 0);
  560. X  last0 = min (last0 + context, files[0].buffered_lines - 1);
  561. X  last1 = min (last1 + context, files[1].buffered_lines - 1);
  562. X
  563. X  /* If desired, find the preceding function definition line in file 0.  */
  564. X  function = 0;
  565. X  if (function_regexp)
  566. X    find_function (&files[0], first0, &function, &function_length);
  567. X
  568. X  /* If we looked for and found a function this is part of,
  569. X     include its name in the header of the diff section.  */
  570. X
  571. X  fprintf (outfile, "@@ -");
  572. X  print_unidiff_number_range (&files[0], first0, last0);
  573. X  fprintf (outfile, " +");
  574. X  print_unidiff_number_range (&files[1], first1, last1);
  575. X  fprintf (outfile, " @@");
  576. X
  577. X  if (function)
  578. X    {
  579. X      putc (' ', outfile);
  580. X      fwrite (function, 1, min (function_length - 1, 40), outfile);
  581. X    }
  582. X  putc ('\n', outfile);
  583. X
  584. X  next = hunk;
  585. X  i = first0;
  586. X  j = first1;
  587. X
  588. X  while (i <= last0 || j <= last1)
  589. X    {
  590. X
  591. X      /* If the line isn't a difference, output the context from file 0. */
  592. X
  593. X      if (!next || i < next->line0)
  594. X    {
  595. X      putc (' ', outfile);
  596. X      print_1_line ((char *)0, &files[0].linbuf[i++]);
  597. X      j++;
  598. X    }
  599. X      else
  600. X    {
  601. X      /* For each difference, first output the deleted part. */
  602. X
  603. X      k = next->deleted;
  604. X      while (k--)
  605. X        {
  606. X          putc ('-', outfile);
  607. X          print_1_line ((char *)0, &files[0].linbuf[i++]);
  608. X        }
  609. X
  610. X      /* Then output the inserted part. */
  611. X
  612. X      k = next->inserted;
  613. X      while (k--)
  614. X        {
  615. X          putc ('+', outfile);
  616. X          print_1_line ((char *)0, &files[1].linbuf[j++]);
  617. X        }
  618. X
  619. X      /* We're done with this hunk, so on to the next! */
  620. X
  621. X      next = next->link;
  622. X    }
  623. X    }
  624. X}
  625. X
  626. X/* Scan a (forward-ordered) edit script for the first place that at least
  627. X   2*CONTEXT unchanged lines appear, and return a pointer
  628. X   to the `struct change' for the last change before those lines.  */
  629. X
  630. Xstatic struct change *
  631. Xfind_hunk (start)
  632. X     struct change *start;
  633. X{
  634. X  struct change *prev;
  635. X  int top0, top1;
  636. X  int thresh;
  637. X
  638. X  do
  639. X    {
  640. X      /* Computer number of first line in each file beyond this changed.  */
  641. X      top0 = start->line0 + start->deleted;
  642. X      top1 = start->line1 + start->inserted;
  643. X      prev = start;
  644. X      start = start->link;
  645. X      /* Threshold distance is 2*CONTEXT between two non-ignorable changes,
  646. X     but only CONTEXT if one is ignorable.  */
  647. X      thresh = ((prev->ignore || (start && start->ignore))
  648. X        ? context
  649. X        : 2 * context);
  650. X      /* It is not supposed to matter which file we check in the end-test.
  651. X     If it would matter, crash.  */
  652. X      if (start && start->line0 - top0 != start->line1 - top1)
  653. X    abort ();
  654. X    } while (start
  655. X         /* Keep going if less than THRESH lines
  656. X        elapse before the affected line.  */
  657. X         && start->line0 < top0 + thresh);
  658. X
  659. X  return prev;
  660. X}
  661. X
  662. X/* Set the `ignore' flag properly in each change in SCRIPT.
  663. X   It should be 1 if all the lines inserted or deleted in that change
  664. X   are ignorable lines.  */
  665. X
  666. Xstatic void
  667. Xmark_ignorable (script)
  668. X     struct change *script;
  669. X{
  670. X  while (script)
  671. X    {
  672. X      struct change *next = script->link;
  673. X      int first0, last0, first1, last1, deletes, inserts;
  674. X
  675. X      /* Turn this change into a hunk: detach it from the others.  */
  676. X      script->link = 0;
  677. X
  678. X      /* Determine whether this change is ignorable.  */
  679. X      analyze_hunk (script, &first0, &last0, &first1, &last1, &deletes, &inserts);
  680. X      /* Reconnect the chain as before.  */
  681. X      script->link = next;
  682. X
  683. X      /* If the change is ignorable, mark it.  */
  684. X      script->ignore = (!deletes && !inserts);
  685. X
  686. X      /* Advance to the following change.  */
  687. X      script = next;
  688. X    }
  689. X}
  690. X
  691. X/* Find the last function-header line in FILE prior to line number LINENUM.
  692. X   This is a line containing a match for the regexp in `function_regexp'.
  693. X   Store the address of the line text into LINEP and the length of the
  694. X   line into LENP.
  695. X   Do not store anything if no function-header is found.  */
  696. X
  697. Xstatic void
  698. Xfind_function (file, linenum, linep, lenp)
  699. X     struct file_data *file;
  700. X     int linenum;
  701. X     char **linep;
  702. X     int *lenp;
  703. X{
  704. X  int i = linenum;
  705. X  int last = find_function_last_search;
  706. X  find_function_last_search = i;
  707. X
  708. X  while (--i >= last)
  709. X    {
  710. X      /* See if this line is what we want.  */
  711. X
  712. X      if (0 <= re_search (&function_regexp_compiled,
  713. X              file->linbuf[i].text,
  714. X              file->linbuf[i].length,
  715. X              0, file->linbuf[i].length,
  716. X              0))
  717. X    {
  718. X      *linep = file->linbuf[i].text;
  719. X      *lenp = file->linbuf[i].length;
  720. X      find_function_last_match = i;
  721. X      return;
  722. X    }
  723. X    }
  724. X  /* If we search back to where we started searching the previous time,
  725. X     find the line we found last time.  */
  726. X  if (find_function_last_match >= 0)
  727. X    {
  728. X      i = find_function_last_match;
  729. X      *linep = file->linbuf[i].text;
  730. X      *lenp = file->linbuf[i].length;
  731. X      return;
  732. X    }
  733. X  return;
  734. X}
  735. END_OF_FILE
  736. if test 12479 -ne `wc -c <'context.c'`; then
  737.     echo shar: \"'context.c'\" unpacked with wrong size!
  738. fi
  739. # end of 'context.c'
  740. fi
  741. if test -f 'diff.h' -a "${1}" != "-c" ; then 
  742.   echo shar: Will not clobber existing file \"'diff.h'\"
  743. else
  744. echo shar: Extracting \"'diff.h'\" \(10400 characters\)
  745. sed "s/^X//" >'diff.h' <<'END_OF_FILE'
  746. X/* Shared definitions for GNU DIFF
  747. X   Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  748. X
  749. XThis file is part of GNU DIFF.
  750. X
  751. XGNU DIFF is free software; you can redistribute it and/or modify
  752. Xit under the terms of the GNU General Public License as published by
  753. Xthe Free Software Foundation; either version 1, or (at your option)
  754. Xany later version.
  755. X
  756. XGNU DIFF is distributed in the hope that it will be useful,
  757. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  758. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  759. XGNU General Public License for more details.
  760. X
  761. XYou should have received a copy of the GNU General Public License
  762. Xalong with GNU DIFF; see the file COPYING.  If not, write to
  763. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  764. X
  765. X
  766. X#include <ctype.h>
  767. X#include <stdio.h>
  768. X#include <sys/types.h>
  769. X#include <sys/stat.h>
  770. X
  771. X#ifdef USG
  772. X#include <time.h>
  773. X#ifdef HAVE_NDIR
  774. X#ifdef NDIR_IN_SYS
  775. X#include <sys/ndir.h>
  776. X#else
  777. X#include <ndir.h>
  778. X#endif /* not NDIR_IN_SYS */
  779. X#else
  780. X#include <dirent.h>
  781. X#endif /* not HAVE_NDIR */
  782. X#include <fcntl.h>
  783. X#ifndef HAVE_DIRECT
  784. X#define direct dirent
  785. X#endif
  786. X#else /* not USG */
  787. X#include <sys/time.h>
  788. X#include <sys/dir.h>
  789. X#include <sys/file.h>
  790. X#endif
  791. X
  792. X#ifdef USG
  793. X/* Define needed BSD functions in terms of sysV library.  */
  794. X
  795. X#define bcopy(s,d,n)    memcpy((d),(s),(n))
  796. X#define bcmp(s1,s2,n)    memcmp((s1),(s2),(n))
  797. X#define bzero(s,n)    memset((s),0,(n))
  798. X
  799. X#ifndef XENIX
  800. X#define dup2(f,t)    (close(t),fcntl((f),F_DUPFD,(t)))
  801. X#endif
  802. X
  803. X#define vfork    fork
  804. X#define index    strchr
  805. X#define rindex    strrchr
  806. X#endif
  807. X
  808. X#ifdef sparc
  809. X/* vfork clobbers registers on the Sparc, so don't use it.  */
  810. X#define vfork fork
  811. X#endif
  812. X
  813. X#include <errno.h>
  814. Xextern int      errno;
  815. Xextern int      sys_nerr;
  816. Xextern char    *sys_errlist[];
  817. X
  818. X#define    EOS        (0)
  819. X#define    FALSE        (0)
  820. X#define TRUE        1
  821. X
  822. X#define min(a,b) ((a) <= (b) ? (a) : (b))
  823. X#define max(a,b) ((a) >= (b) ? (a) : (b))
  824. X
  825. X#ifndef PR_FILE_NAME
  826. X#define PR_FILE_NAME "/bin/pr"
  827. X#endif
  828. X
  829. X/* Support old-fashioned C compilers.  */
  830. X#if defined (__STDC__) || defined (__GNUC__)
  831. X#include "limits.h"
  832. X#else
  833. X#define INT_MAX 2147483647
  834. X#define CHAR_BIT 8
  835. X#endif
  836. X
  837. X/* Support old-fashioned C compilers.  */
  838. X#if !defined (__STDC__) && !defined (__GNUC__)
  839. X#define const
  840. X#endif
  841. X
  842. X#ifndef O_RDONLY
  843. X#define O_RDONLY 0
  844. X#endif
  845. X
  846. X/* Variables for command line options */
  847. X
  848. X#ifndef GDIFF_MAIN
  849. X#define EXTERN extern
  850. X#else
  851. X#define EXTERN
  852. X#endif
  853. X
  854. Xenum output_style {
  855. X  /* Default output style.  */
  856. X  OUTPUT_NORMAL,
  857. X  /* Output the differences with lines of context before and after (-c).  */
  858. X  OUTPUT_CONTEXT,
  859. X  /* Output the differences in a unified context diff format (-u). */
  860. X  OUTPUT_UNIFIED,
  861. X  /* Output the differences as commands suitable for `ed' (-e).  */
  862. X  OUTPUT_ED,
  863. X  /* Output the diff as a forward ed script (-f).  */
  864. X  OUTPUT_FORWARD_ED,
  865. X  /* Like -f, but output a count of changed lines in each "command" (-n). */
  866. X  OUTPUT_RCS,
  867. X  /* Output merged #ifdef'd file (-D).  */
  868. X  OUTPUT_IFDEF };
  869. X
  870. X/* True for output styles that are robust,
  871. X   i.e. can handle a file that ends in a non-newline.  */
  872. X#define ROBUST_OUTPUT_STYLE(S) \
  873. X ((S) == OUTPUT_CONTEXT || (S) == OUTPUT_UNIFIED || (S) == OUTPUT_RCS \
  874. X  || (S) == OUTPUT_NORMAL)
  875. X
  876. XEXTERN enum output_style output_style;
  877. X
  878. X/* Number of lines of context to show in each set of diffs.
  879. X   This is zero when context is not to be shown.  */
  880. XEXTERN int      context;
  881. X
  882. X/* Consider all files as text files (-a).
  883. X   Don't interpret codes over 0177 as implying a "binary file".  */
  884. XEXTERN int    always_text_flag;
  885. X
  886. X/* Ignore changes in horizontal whitespace (-b).  */
  887. XEXTERN int      ignore_space_change_flag;
  888. X
  889. X/* Ignore all horizontal whitespace (-w).  */
  890. XEXTERN int      ignore_all_space_flag;
  891. X
  892. X/* Ignore changes that affect only blank lines (-B).  */
  893. XEXTERN int      ignore_blank_lines_flag;
  894. X
  895. X/* Ignore changes that affect only lines matching this regexp (-I).  */
  896. XEXTERN char    *ignore_regexp;
  897. X
  898. X/* Result of regex-compilation of `ignore_regexp'.  */
  899. XEXTERN struct re_pattern_buffer ignore_regexp_compiled;
  900. X
  901. X/* 1 if lines may match even if their lengths are different.
  902. X   This depends on various options.  */
  903. XEXTERN int      length_varies;
  904. X
  905. X/* Ignore differences in case of letters (-i).  */
  906. XEXTERN int      ignore_case_flag;
  907. X
  908. X/* File labels for `-c' output headers (-L).  */
  909. XEXTERN char *file_label[2];
  910. X
  911. X/* Regexp to identify function-header lines (-F).  */
  912. XEXTERN char    *function_regexp;
  913. X
  914. X/* Result of regex-compilation of `function_regexp'.  */
  915. XEXTERN struct re_pattern_buffer function_regexp_compiled;
  916. X
  917. X/* Say only whether files differ, not how (-q).  */
  918. XEXTERN int     no_details_flag;
  919. X
  920. X/* Report files compared that match (-s).
  921. X   Normally nothing is output when that happens.  */
  922. XEXTERN int      print_file_same_flag;
  923. X
  924. X/* character that ends a line.  Currently this is always `\n'.  */
  925. XEXTERN char     line_end_char;
  926. X
  927. X/* Output the differences with exactly 8 columns added to each line
  928. X   so that any tabs in the text line up properly (-T).  */
  929. XEXTERN int    tab_align_flag;
  930. X
  931. X/* Expand tabs in the output so the text lines up properly
  932. X   despite the characters added to the front of each line (-t).  */
  933. XEXTERN int    tab_expand_flag;
  934. X
  935. X/* In directory comparison, specify file to start with (-S).
  936. X   All file names less than this name are ignored.  */
  937. XEXTERN char    *dir_start_file;
  938. X
  939. X/* If a file is new (appears in only one dir)
  940. X   include its entire contents (-N).
  941. X   Then `patch' would create the file with appropriate contents.  */
  942. XEXTERN int    entire_new_file_flag;
  943. X
  944. X/* Pipe each file's output through pr (-l).  */
  945. XEXTERN int    paginate_flag;
  946. X
  947. X/* String to use for #ifdef (-D).  */
  948. XEXTERN char *    ifdef_string;
  949. X
  950. X/* String containing all the command options diff received,
  951. X   with spaces between and at the beginning but none at the end.
  952. X   If there were no options given, this string is empty.  */
  953. XEXTERN char *    switch_string;
  954. X
  955. X/* Nonzero means use heuristics for better speed.  */
  956. XEXTERN int    heuristic;
  957. X
  958. X/* Name of program the user invoked (for error messages).  */
  959. XEXTERN char *    program;
  960. X
  961. X/* The result of comparison is an "edit script": a chain of `struct change'.
  962. X   Each `struct change' represents one place where some lines are deleted
  963. X   and some are inserted.
  964. X   
  965. X   LINE0 and LINE1 are the first affected lines in the two files (origin 0).
  966. X   DELETED is the number of lines deleted here from file 0.
  967. X   INSERTED is the number of lines inserted here in file 1.
  968. X
  969. X   If DELETED is 0 then LINE0 is the number of the line before
  970. X   which the insertion was done; vice versa for INSERTED and LINE1.  */
  971. X
  972. Xstruct change
  973. X{
  974. X  struct change *link;        /* Previous or next edit command  */
  975. X  int inserted;            /* # lines of file 1 changed here.  */
  976. X  int deleted;            /* # lines of file 0 changed here.  */
  977. X  int line0;            /* Line number of 1st deleted line.  */
  978. X  int line1;            /* Line number of 1st inserted line.  */
  979. X  char ignore;            /* Flag used in context.c */
  980. X};
  981. X
  982. X/* Structures that describe the input files.  */
  983. X
  984. X/* Data on one line of text.  */
  985. X
  986. Xstruct line_def {
  987. X    char        *text;
  988. X    int         length;
  989. X    unsigned    hash;
  990. X};
  991. X
  992. X/* Data on one input file being compared.  */
  993. X
  994. Xstruct file_data {
  995. X    int             desc;    /* File descriptor  */
  996. X    char           *name;    /* File name  */
  997. X    struct stat     stat;    /* File status from fstat()  */
  998. X    int             dir_p;    /* 1 if file is a directory  */
  999. X
  1000. X    /* Buffer in which text of file is read.  */
  1001. X    char *        buffer;
  1002. X    /* Allocated size of buffer.  */
  1003. X    int            bufsize;
  1004. X    /* Number of valid characters now in the buffer. */
  1005. X    int            buffered_chars;
  1006. X
  1007. X    /* Array of data on analyzed lines of this chunk of this file.  */
  1008. X    struct line_def *linbuf;
  1009. X
  1010. X    /* Allocated size of linbuf array (# of elements).  */
  1011. X    int            linbufsize;
  1012. X
  1013. X    /* Number of elements of linbuf containing valid data. */
  1014. X    int            buffered_lines;
  1015. X
  1016. X    /* Pointer to end of prefix of this file to ignore when hashing. */
  1017. X    char *prefix_end;
  1018. X
  1019. X    /* Count of lines in the prefix. */
  1020. X    int prefix_lines;
  1021. X
  1022. X    /* Pointer to start of suffix of this file to ignore when hashing. */
  1023. X    char *suffix_begin;
  1024. X
  1025. X    /* Count of lines in the suffix. */
  1026. X    int suffix_lines;
  1027. X
  1028. X    /* Vector, indexed by line number, containing an equivalence code for
  1029. X       each line.  It is this vector that is actually compared with that
  1030. X       of another file to generate differences. */
  1031. X    int           *equivs;
  1032. X
  1033. X    /* Vector, like the previous one except that
  1034. X       the elements for discarded lines have been squeezed out.  */
  1035. X    int           *undiscarded;
  1036. X
  1037. X    /* Vector mapping virtual line numbers (not counting discarded lines)
  1038. X       to real ones (counting those lines).  Both are origin-0.  */
  1039. X    int           *realindexes;
  1040. X
  1041. X    /* Total number of nondiscarded lines. */
  1042. X    int            nondiscarded_lines;
  1043. X
  1044. X    /* Vector, indexed by real origin-0 line number,
  1045. X       containing 1 for a line that is an insertion or a deletion.
  1046. X       The results of comparison are stored here.  */
  1047. X    char       *changed_flag;
  1048. X
  1049. X    /* 1 if file ends in a line with no final newline. */
  1050. X    int            missing_newline;
  1051. X
  1052. X    /* 1 more than the maximum equivalence value used for this or its
  1053. X       sibling file. */
  1054. X    int equiv_max;
  1055. X
  1056. X    /* Table translating diff's internal line numbers 
  1057. X       to actual line numbers in the file.
  1058. X       This is needed only when some lines have been discarded.
  1059. X       The allocated size is always linbufsize
  1060. X       and the number of valid elements is buffered_lines.  */
  1061. X    int           *ltran;
  1062. X};
  1063. X
  1064. X/* Describe the two files currently being compared.  */
  1065. X
  1066. Xstruct file_data files[2];
  1067. X
  1068. X/* Queue up one-line messages to be printed at the end,
  1069. X   when -l is specified.  Each message is recorded with a `struct msg'.  */
  1070. X
  1071. Xstruct msg
  1072. X{
  1073. X  struct msg *next;
  1074. X  char *format;
  1075. X  char *arg1;
  1076. X  char *arg2;
  1077. X};
  1078. X
  1079. X/* Head of the chain of queues messages.  */
  1080. X
  1081. XEXTERN struct msg *msg_chain;
  1082. X
  1083. X/* Tail of the chain of queues messages.  */
  1084. X
  1085. XEXTERN struct msg *msg_chain_end;
  1086. X
  1087. X/* Stdio stream to output diffs to.  */
  1088. X
  1089. XEXTERN FILE *outfile;
  1090. X
  1091. X/* Declare various functions.  */
  1092. X
  1093. X#ifdef __STDC__
  1094. X#define VOID void
  1095. X#else
  1096. X#define VOID char
  1097. X#endif
  1098. XVOID *xmalloc ();
  1099. XVOID *xrealloc ();
  1100. Xchar *concat ();
  1101. Xvoid free ();
  1102. Xchar *rindex ();
  1103. Xchar *index ();
  1104. X
  1105. Xvoid analyze_hunk ();
  1106. Xvoid error ();
  1107. Xvoid fatal ();
  1108. Xvoid message ();
  1109. Xvoid perror_with_name ();
  1110. Xvoid pfatal_with_name ();
  1111. Xvoid print_1_line ();
  1112. Xvoid print_message_queue ();
  1113. Xvoid print_number_range ();
  1114. Xvoid print_script ();
  1115. Xvoid translate_range ();
  1116. END_OF_FILE
  1117. if test 10400 -ne `wc -c <'diff.h'`; then
  1118.     echo shar: \"'diff.h'\" unpacked with wrong size!
  1119. fi
  1120. # end of 'diff.h'
  1121. fi
  1122. if test -f 'regex.h' -a "${1}" != "-c" ; then 
  1123.   echo shar: Will not clobber existing file \"'regex.h'\"
  1124. else
  1125. echo shar: Extracting \"'regex.h'\" \(9584 characters\)
  1126. sed "s/^X//" >'regex.h' <<'END_OF_FILE'
  1127. X/* Definitions for data structures callers pass the regex library.
  1128. X
  1129. X   Copyright (C) 1985, 1989-90 Free Software Foundation, Inc.
  1130. X
  1131. X   This program is free software; you can redistribute it and/or modify
  1132. X   it under the terms of the GNU General Public License as published by
  1133. X   the Free Software Foundation; either version 1, or (at your option)
  1134. X   any later version.
  1135. X
  1136. X   This program is distributed in the hope that it will be useful,
  1137. X   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1138. X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1139. X   GNU General Public License for more details.
  1140. X
  1141. X   You should have received a copy of the GNU General Public License
  1142. X   along with this program; if not, write to the Free Software
  1143. X   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1144. X
  1145. X
  1146. X#ifdef __GNUC__
  1147. X  #pragma once
  1148. X#endif
  1149. X
  1150. X#ifndef __REGEXP_LIBRARY
  1151. X#define __REGEXP_LIBRARY
  1152. X
  1153. X/* Define number of parens for which we record the beginnings and ends.
  1154. X   This affects how much space the `struct re_registers' type takes up.  */
  1155. X#ifndef RE_NREGS
  1156. X#define RE_NREGS 10
  1157. X#endif
  1158. X
  1159. X#define BYTEWIDTH 8
  1160. X
  1161. X
  1162. X/* Maximum number of duplicates an interval can allow.  */
  1163. X#define RE_DUP_MAX  ((1 << 15) - 1) 
  1164. X
  1165. X
  1166. X/* This defines the various regexp syntaxes.  */
  1167. Xextern int obscure_syntax;
  1168. X
  1169. X
  1170. X/* The following bits are used in the obscure_syntax variable to choose among
  1171. X   alternative regexp syntaxes.  */
  1172. X
  1173. X/* If this bit is set, plain parentheses serve as grouping, and backslash
  1174. X     parentheses are needed for literal searching.
  1175. X   If not set, backslash-parentheses are grouping, and plain parentheses
  1176. X     are for literal searching.  */
  1177. X#define RE_NO_BK_PARENS    1
  1178. X
  1179. X/* If this bit is set, plain | serves as the `or'-operator, and \| is a 
  1180. X     literal.
  1181. X   If not set, \| serves as the `or'-operator, and | is a literal.  */
  1182. X#define RE_NO_BK_VBAR (1 << 1)
  1183. X
  1184. X/* If this bit is not set, plain + or ? serves as an operator, and \+, \? are 
  1185. X     literals.
  1186. X   If set, \+, \? are operators and plain +, ? are literals.  */
  1187. X#define RE_BK_PLUS_QM (1 << 2)
  1188. X
  1189. X/* If this bit is set, | binds tighter than ^ or $.
  1190. X   If not set, the contrary.  */
  1191. X#define RE_TIGHT_VBAR (1 << 3)
  1192. X
  1193. X/* If this bit is set, then treat newline as an OR operator.
  1194. X   If not set, treat it as a normal character.  */
  1195. X#define RE_NEWLINE_OR (1 << 4)
  1196. X
  1197. X/* If this bit is set, then special characters may act as normal
  1198. X   characters in some contexts. Specifically, this applies to:
  1199. X    ^ -- only special at the beginning, or after ( or |;
  1200. X    $ -- only special at the end, or before ) or |;
  1201. X    *, +, ? -- only special when not after the beginning, (, or |.
  1202. X   If this bit is not set, special characters (such as *, ^, and $)
  1203. X   always have their special meaning regardless of the surrounding
  1204. X   context.  */
  1205. X#define RE_CONTEXT_INDEP_OPS (1 << 5)
  1206. X
  1207. X/* If this bit is not set, then \ before anything inside [ and ] is taken as 
  1208. X     a real \.
  1209. X   If set, then such a \ escapes the following character.  This is a
  1210. X     special case for awk.  */
  1211. X#define RE_AWK_CLASS_HACK (1 << 6)
  1212. X
  1213. X/* If this bit is set, then \{ and \} or { and } serve as interval operators.
  1214. X   If not set, then \{ and \} and { and } are treated as literals.  */
  1215. X#define RE_INTERVALS (1 << 7)
  1216. X
  1217. X/* If this bit is not set, then \{ and \} serve as interval operators and 
  1218. X     { and } are literals.
  1219. X   If set, then { and } serve as interval operators and \{ and \} are 
  1220. X     literals.  */
  1221. X#define RE_NO_BK_CURLY_BRACES (1 << 8)
  1222. X
  1223. X/* If this bit is set, then character classes are supported; they are:
  1224. X     [:alpha:],    [:upper:], [:lower:],  [:digit:], [:alnum:], [:xdigit:],
  1225. X     [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
  1226. X   If not set, then character classes are not supported.  */
  1227. X#define RE_CHAR_CLASSES (1 << 9)
  1228. X
  1229. X/* If this bit is set, then the dot re doesn't match a null byte.
  1230. X   If not set, it does.  */
  1231. X#define RE_DOT_NOT_NULL (1 << 10)
  1232. X
  1233. X/* If this bit is set, then [^...] doesn't match a newline.
  1234. X   If not set, it does.  */
  1235. X#define RE_HAT_NOT_NEWLINE (1 << 11)
  1236. X
  1237. X/* If this bit is set, back references are recognized.
  1238. X   If not set, they aren't.  */
  1239. X#define RE_NO_BK_REFS (1 << 12)
  1240. X
  1241. X/* If this bit is set, back references must refer to a preceding
  1242. X   subexpression.  If not set, a back reference to a nonexistent
  1243. X   subexpression is treated as literal characters.  */
  1244. X#define RE_NO_EMPTY_BK_REF (1 << 13)
  1245. X
  1246. X/* If this bit is set, bracket expressions can't be empty.  
  1247. X   If it is set, they can be empty.  */
  1248. X#define RE_NO_EMPTY_BRACKETS (1 << 14)
  1249. X
  1250. X/* If this bit is set, then *, +, ? and { cannot be first in an re or
  1251. X   immediately after a |, or a (.  Furthermore, a | cannot be first or
  1252. X   last in an re, or immediately follow another | or a (.  Also, a ^
  1253. X   cannot appear in a nonleading position and a $ cannot appear in a
  1254. X   nontrailing position (outside of bracket expressions, that is).  */
  1255. X#define RE_CONTEXTUAL_INVALID_OPS (1 << 15)
  1256. X
  1257. X/* If this bit is set, then +, ? and | aren't recognized as operators.
  1258. X   If it's not, they are.  */
  1259. X#define RE_LIMITED_OPS (1 << 16)
  1260. X
  1261. X/* If this bit is set, then an ending range point has to collate higher
  1262. X     or equal to the starting range point.
  1263. X   If it's not set, then when the ending range point collates higher
  1264. X     than the starting range point, the range is just considered empty.  */
  1265. X#define RE_NO_EMPTY_RANGES (1 << 17)
  1266. X
  1267. X/* If this bit is set, then a hyphen (-) can't be an ending range point.
  1268. X   If it isn't, then it can.  */
  1269. X#define RE_NO_HYPHEN_RANGE_END (1 << 18)
  1270. X
  1271. X
  1272. X/* Define combinations of bits for the standard possibilities.  */
  1273. X#define RE_SYNTAX_POSIX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR \
  1274. X            | RE_CONTEXT_INDEP_OPS)
  1275. X#define RE_SYNTAX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR \
  1276. X            | RE_CONTEXT_INDEP_OPS | RE_AWK_CLASS_HACK)
  1277. X#define RE_SYNTAX_EGREP (RE_NO_BK_PARENS | RE_NO_BK_VBAR \
  1278. X            | RE_CONTEXT_INDEP_OPS | RE_NEWLINE_OR)
  1279. X#define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR)
  1280. X#define RE_SYNTAX_EMACS 0
  1281. X#define RE_SYNTAX_POSIX_BASIC (RE_INTERVALS | RE_BK_PLUS_QM         \
  1282. X            | RE_CHAR_CLASSES | RE_DOT_NOT_NULL         \
  1283. X                        | RE_HAT_NOT_NEWLINE | RE_NO_EMPTY_BK_REF     \
  1284. X                        | RE_NO_EMPTY_BRACKETS | RE_LIMITED_OPS        \
  1285. X                        | RE_NO_EMPTY_RANGES | RE_NO_HYPHEN_RANGE_END)    
  1286. X                        
  1287. X#define RE_SYNTAX_POSIX_EXTENDED (RE_INTERVALS | RE_NO_BK_CURLY_BRACES       \
  1288. X            | RE_NO_BK_VBAR | RE_NO_BK_PARENS            \
  1289. X                        | RE_HAT_NOT_NEWLINE | RE_CHAR_CLASSES            \
  1290. X                        | RE_NO_EMPTY_BRACKETS | RE_CONTEXTUAL_INVALID_OPS \
  1291. X                        | RE_NO_BK_REFS | RE_NO_EMPTY_RANGES            \
  1292. X                        | RE_NO_HYPHEN_RANGE_END)
  1293. X
  1294. X
  1295. X/* This data structure is used to represent a compiled pattern.  */
  1296. X
  1297. Xstruct re_pattern_buffer
  1298. X  {
  1299. X    char *buffer;    /* Space holding the compiled pattern commands.  */
  1300. X    long allocated;    /* Size of space that `buffer' points to. */
  1301. X    long used;        /* Length of portion of buffer actually occupied  */
  1302. X    char *fastmap;    /* Pointer to fastmap, if any, or zero if none.  */
  1303. X            /* re_search uses the fastmap, if there is one,
  1304. X               to skip over totally implausible characters.  */
  1305. X    char *translate;    /* Translate table to apply to all characters before 
  1306. X                   comparing, or zero for no translation.
  1307. X               The translation is applied to a pattern when it is 
  1308. X                           compiled and to data when it is matched.  */
  1309. X    char fastmap_accurate;
  1310. X            /* Set to zero when a new pattern is stored,
  1311. X               set to one when the fastmap is updated from it.  */
  1312. X    char can_be_null;   /* Set to one by compiling fastmap
  1313. X               if this pattern might match the null string.
  1314. X               It does not necessarily match the null string
  1315. X               in that case, but if this is zero, it cannot.
  1316. X               2 as value means can match null string
  1317. X               but at end of range or before a character
  1318. X               listed in the fastmap.  */
  1319. X  };
  1320. X
  1321. X
  1322. X/* search.c (search_buffer) needs this one value.  It is defined both in
  1323. X   regex.c and here.  */
  1324. X#define RE_EXACTN_VALUE 1
  1325. X
  1326. X
  1327. X/* Structure to store register contents data in.
  1328. X
  1329. X   Pass the address of such a structure as an argument to re_match, etc.,
  1330. X   if you want this information back.
  1331. X
  1332. X   For i from 1 to RE_NREGS - 1, start[i] records the starting index in
  1333. X   the string of where the ith subexpression matched, and end[i] records
  1334. X   one after the ending index.  start[0] and end[0] are analogous, for
  1335. X   the entire pattern.  */
  1336. X
  1337. Xstruct re_registers
  1338. X  {
  1339. X    int start[RE_NREGS];
  1340. X    int end[RE_NREGS];
  1341. X  };
  1342. X
  1343. X
  1344. X
  1345. X#ifdef __STDC__
  1346. X
  1347. Xextern char *re_compile_pattern (char *, int, struct re_pattern_buffer *);
  1348. X/* Is this really advertised?  */
  1349. Xextern void re_compile_fastmap (struct re_pattern_buffer *);
  1350. Xextern int re_search (struct re_pattern_buffer *, char*, int, int, int,
  1351. X              struct re_registers *);
  1352. Xextern int re_search_2 (struct re_pattern_buffer *, char *, int,
  1353. X            char *, int, int, int,
  1354. X            struct re_registers *, int);
  1355. Xextern int re_match (struct re_pattern_buffer *, char *, int, int,
  1356. X             struct re_registers *);
  1357. Xextern int re_match_2 (struct re_pattern_buffer *, char *, int,
  1358. X               char *, int, int, struct re_registers *, int);
  1359. X
  1360. X/* 4.2 bsd compatibility.  */
  1361. Xextern char *re_comp (char *);
  1362. Xextern int re_exec (char *);
  1363. X
  1364. X#else /* !__STDC__ */
  1365. X
  1366. Xextern char *re_compile_pattern ();
  1367. X/* Is this really advertised? */
  1368. Xextern void re_compile_fastmap ();
  1369. Xextern int re_search (), re_search_2 ();
  1370. Xextern int re_match (), re_match_2 ();
  1371. X
  1372. X/* 4.2 bsd compatibility.  */
  1373. Xextern char *re_comp ();
  1374. Xextern int re_exec ();
  1375. X
  1376. X#endif /* __STDC__ */
  1377. X
  1378. X
  1379. X#ifdef SYNTAX_TABLE
  1380. Xextern char *re_syntax_table;
  1381. X#endif
  1382. X
  1383. X#endif /* !__REGEXP_LIBRARY */
  1384. END_OF_FILE
  1385. if test 9584 -ne `wc -c <'regex.h'`; then
  1386.     echo shar: \"'regex.h'\" unpacked with wrong size!
  1387. fi
  1388. # end of 'regex.h'
  1389. fi
  1390. echo shar: End of archive 2 \(of 8\).
  1391. cp /dev/null ark2isdone
  1392. MISSING=""
  1393. for I in 1 2 3 4 5 6 7 8 ; do
  1394.     if test ! -f ark${I}isdone ; then
  1395.     MISSING="${MISSING} ${I}"
  1396.     fi
  1397. done
  1398. if test "${MISSING}" = "" ; then
  1399.     echo You have unpacked all 8 archives.
  1400.     rm -f ark[1-9]isdone
  1401. else
  1402.     echo You still need to unpack the following archives:
  1403.     echo "        " ${MISSING}
  1404. fi
  1405. ##  End of shell archive.
  1406. exit 0
  1407.  
  1408. exit 0 # Just in case...
  1409.